package model;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

public class StringFactory {
	public static String getAleaString(int len) {
		String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
		String s = "";
		for (int x = 0; x < len; x++) {
			int y = (int) Math.floor(Math.random() * 62);
			s += chars.charAt(y);
		}
		return s;
	}

	public static String getAleaProtein() {
		InputStream fis;
		BufferedReader br;
		String line = new String();

		try {
			fis = new FileInputStream("Proteins.txt");
			br = new BufferedReader(new InputStreamReader(fis,Charset.forName("UTF-8")));
			int lineNb = (int) Math.floor(Math.random() * 3296);
			for (int i = 0; i < lineNb; ++i)
				br.readLine();
			line = br.readLine();
			br.close();
			br = null;
			fis = null;
		} catch (Exception e) {
			e.printStackTrace();
		}

		return line;

	}

	public static String getAleaWord() {
		InputStream fis;
		BufferedReader br;
		String line = new String();

		try {
			fis = new FileInputStream("Dictionary.txt");
			br = new BufferedReader(new InputStreamReader(fis,Charset.forName("UTF-8")));
			int lineNb = (int) Math.floor(Math.random() * 45402);
			for (int i = 0; i < lineNb; ++i)
				br.readLine();
			line = br.readLine();
			br.close();
			br = null;
			fis = null;
		} catch (Exception e) {
			e.printStackTrace();
		}

		return line;
	}

	public static String getAleaWords(int len) {
		InputStream fis;
		BufferedReader br;
		String line = new String();
		
		String sentence="";
		for (int j=0;j<len;j++){
			try {
				fis = new FileInputStream("Dictionary.txt");
				br = new BufferedReader(new InputStreamReader(fis,Charset.forName("UTF-8")));
				int lineNb = (int) Math.floor(Math.random() * 45402);
				for (int i = 0; i < lineNb; ++i)
					br.readLine();
				line = br.readLine();
				br.close();
				br = null;
				fis = null;
			} catch (Exception e) {
				e.printStackTrace();
			}	
			sentence += line;
		}

		return sentence;
	}
}
